`
https://leetcode.cn/problems/mice-and-cheese/
`

/**
 * @param {number[]} reward1
 * @param {number[]} reward2
 * @param {number} k
 * @return {number}
 */
var miceAndCheese = function (reward1, reward2, k) {
  const n = reward1.length;
  // 创建一个数组存储索引和差值
  const diffs = [];
  for (let i = 0; i < n; i++) {
    diffs.push({
      index: i,
      diff: reward1[i] - reward2[i]
    });
  }

  // 按差值从大到小排序
  diffs.sort((a, b) => b.diff - a.diff);

  let total = 0;
  // 第一只老鼠吃前k个差值最大的奶酪
  for (let i = 0; i < k; i++) {
    total += reward1[diffs[i].index];
  }
  // 第二只老鼠吃剩下的奶酪
  for (let i = k; i < n; i++) {
    total += reward2[diffs[i].index];
  }

  return total;
};